﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;
using EnvDTE;
using TSVNAddin.SVN;

namespace TSVNAddin.Core.Test
{
	[TestFixture]
	public class ProjectActionExecutorFixture
	{
		[Test]
		public void OnProjectAddedShouldAddFileOnVersionControl()
		{
			var project = MockRepository.GenerateStub<Project>();
			project.Stub(x => x.FullName).Return(@"c:\myproject\myproject.csproj");
			var addedAction = MockRepository.GenerateStub<PathAddedAction>(null, null);
			var projectItemsRecover = MockRepository.GenerateStub<ProjectItemsRecover>();
			projectItemsRecover.Stub(x => x.GetItemPaths(project)).Return(new string[] { @"c:\myproject\class1.cs", @"c:\myproject\class2.cs" });

			var versionControl = MockRepository.GenerateStub<IVersionControl>();

			var projectActionExecutor = new ProjectActionExecutor(
				new ProjectAddedAction(addedAction, projectItemsRecover, versionControl),
				null,
				null);

			projectActionExecutor.NotifyAdded(project);

			addedAction.AssertWasCalled(x => x.Execute(@"c:\myproject\myproject.csproj"));
			addedAction.AssertWasCalled(x => x.Execute(@"c:\myproject\class1.cs"));
			addedAction.AssertWasCalled(x => x.Execute(@"c:\myproject\class2.cs"));
			versionControl.AssertWasCalled(x => x.AddToIgnoreList(@"c:\myproject", "bin"));
			versionControl.AssertWasCalled(x => x.AddToIgnoreList(@"c:\myproject", "obj"));
		}

		[Test]
		public void OnProjectRemovedShouldDeleteFileOnVersionControl()
		{
			var project = MockRepository.GenerateStub<Project>();
			project.Stub(x => x.FullName).Return(@"c:\myproject\myproject.csproj");
			var removedAction = MockRepository.GenerateStub<PathRemovedAction>((IVersionControl)null);

			var projectActionExecutor = new ProjectActionExecutor(null, removedAction, null);
			projectActionExecutor.NotifyRemoved(project);

			removedAction.AssertWasCalled(x => x.Execute(@"c:\myproject"));
		}

		[Test]
		public void OnProjectRenamedShouldMoveFileOnVersionControl()
		{
			var project = MockRepository.GenerateStub<Project>();
			project.Stub(x => x.FullName).Return(@"c:\newCiccio.csproj");
			var renamedAction = MockRepository.GenerateStub<PathRenamedAction>(null, null);

			var projectActionExecutor = new ProjectActionExecutor(null, null, renamedAction);
			projectActionExecutor.NotifyRenamed(project, @"oldCiccio.csproj");

			renamedAction.AssertWasCalled(x => x.Execute(@"c:\newCiccio.csproj", @"oldCiccio.csproj"));
		}
	}
}
